package com.spring.demo.spring_boot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.Cacheable;

import com.spring.demo.spring_boot.base.mapper.BaseMapper;
import com.spring.demo.spring_boot.domain.UserRole;

/**
 * 
 * @author 王辉阳
 * @date 2017年8月1日 下午6:11:28
 * @description 用户映射器
 */
@Mapper
public interface UserRoleMapper extends BaseMapper<UserRole> {
	// 查询后存入redis，建议以方法名
	@Cacheable(value = "get", keyGenerator = "keyGenerator")
	@Select("SELECT * FROM user_roles WHERE id = #{id}")
	UserRole get(@Param("id") String id);

	@Select("SELECT * FROM user_roles  ")
	List<UserRole> findAll();

	@Results(id = "USER_ID", value = { //
			@Result(property = "userId", column = "USER_ID", id = true), //
			@Result(property = "loginName", column = "LOGIN_NAME"), //
			@Result(property = "loginType", column = "LOGIN_TYPE"), //
			@Result(property = "roleId", column = "ROLE_ID") }) //
	@Select("SELECT * FROM user_roles WHERE USER_ID = #{userId} ")
	List<UserRole> findByUserId(String userId);

}